package cn.wolfcode.education.service.impl;

import cn.wolfcode.education.domain.Classgrade;
import cn.wolfcode.education.mapper.ClassgradeMapper;
import cn.wolfcode.education.query.QueryObject;
import cn.wolfcode.education.service.IClassgradeService;
import cn.wolfcode.education.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassgradeServiceImpl implements IClassgradeService {
    @Autowired
    ClassgradeMapper classgradeMapper;

    //分页
    public PageResult query(QueryObject qo) {
        int total = classgradeMapper.queryForCount(qo);
        if (total == 0) {
            return new PageResult();
        }
        List<Classgrade> rows = classgradeMapper.queryForList();
        return new PageResult(total, rows);
    }

    //保存
    public void save(Classgrade classgrade) {
        classgradeMapper.insert(classgrade);
    }

    //删除
    public void delete(Long id) {
        classgradeMapper.deleteByPrimaryKey(id);
    }

    //编辑
    public void update(Classgrade classgrade) {
        classgradeMapper.updateByPrimaryKey(classgrade);
    }

    public void updateTeacher(Long id) {
        classgradeMapper.updateTeacher(id);
    }

    public List<Classgrade> queryAll() {
        return classgradeMapper.selectAll();
    }

    public PageResult queryByClassroomId(Long classroomId) {
        List<Classgrade> list = classgradeMapper.queryByClassroomId(classroomId);
        if (list.size() == 0){
            return new PageResult();
        }
        return new PageResult(list.size(),list);
    }

    public List<Classgrade> getAllClassgrade() {
        return classgradeMapper.getAllClassgrade();
    }
}
